package com.jy.oms.framework.asyn.task.model;

import com.jy.oms.framework.asyn.task.constants.TaskQueueTypeEnum;
import com.jy.oms.framework.asyn.task.core.ExecutorFailoverConfig;
import com.jy.oms.framework.asyn.task.handler.ITaskHandler;
import com.jy.oms.framework.asyn.task.model.strategy.ExecuteStrategyObj;
import com.jy.oms.framework.asyn.task.model.strategy.LimiterExecuteStrategy;

public class TaskHandlerWrapper {

    /**
     * 任务编码
     */
    private String taskCode;

    /**
     * 任务组
     */
    private TaskGroup taskGroup;

    /**
     * 任务执行策略
     */
    private ExecuteStrategyObj executeStrategy;

    /**
     * 任务处理器
     */
    private ITaskHandler taskHandler;

    /**
     * 任务处理器执行方法参数类型
     */
    private Class<?> taskHandlerParamType;

    /**
     * 任务处理器执行方法返回值类型
     */
    private Class<?> taskHandlerResultType;

    /**
     * 任务存储的队列类型
     */
    private TaskQueueTypeEnum taskQueue;

    /**
     * 任务配置
     */
    private TaskConfig taskConfig;

    /**
     * 是否需要限流
     */
    private boolean needRateLimit;

    /**
     * 是否能运行任务
     *
     * @see ExecutorFailoverConfig
     */
    private boolean enableExecute = true;

    /**
     * 当添加的任务不在可运行任务组时，是否允许添加任务
     */
    private boolean enableAddTaskIfUnableExecute;

    /**
     * 当允许添加不能运行的任务时，设置的任务组名称
     */
    private String defaultTaskGroupIfUnableExecute;

    /**
     * 是否允许动态设置限流
     */
    public boolean isAdjustableRateLimiter() {
        if (!needRateLimit) {
            return false;
        }

        LimiterExecuteStrategy limiterExecuteStrategy = (LimiterExecuteStrategy) executeStrategy;
        return limiterExecuteStrategy.isAdjustable();
    }

    public String getTaskCode() {
        return taskCode;
    }

    public TaskHandlerWrapper setTaskCode(String taskCode) {
        this.taskCode = taskCode;
        return this;
    }

    public TaskGroup getTaskGroup() {
        return taskGroup;
    }

    public void setTaskGroup(TaskGroup taskGroup) {
        this.taskGroup = taskGroup;
    }

    public ExecuteStrategyObj getExecuteStrategy() {
        return executeStrategy;
    }

    public TaskHandlerWrapper setExecuteStrategy(ExecuteStrategyObj executeStrategy) {
        this.executeStrategy = executeStrategy;
        return this;
    }

    public ITaskHandler getTaskHandler() {
        return taskHandler;
    }

    public TaskHandlerWrapper setTaskHandler(ITaskHandler taskHandler) {
        this.taskHandler = taskHandler;
        return this;
    }

    public Class<?> getTaskHandlerParamType() {
        return taskHandlerParamType;
    }

    public TaskHandlerWrapper setTaskHandlerParamType(Class<?> taskHandlerParamType) {
        this.taskHandlerParamType = taskHandlerParamType;
        return this;
    }

    public Class<?> getTaskHandlerResultType() {
        return taskHandlerResultType;
    }

    public TaskHandlerWrapper setTaskHandlerResultType(Class<?> taskHandlerResultType) {
        this.taskHandlerResultType = taskHandlerResultType;
        return this;
    }

    public TaskQueueTypeEnum getTaskQueue() {
        return taskQueue;
    }

    public TaskHandlerWrapper setTaskQueue(TaskQueueTypeEnum taskQueue) {
        this.taskQueue = taskQueue;
        return this;
    }

    public TaskConfig getTaskConfig() {
        return taskConfig;
    }

    public TaskHandlerWrapper setTaskConfig(TaskConfig taskConfig) {
        this.taskConfig = taskConfig;
        return this;
    }

    public boolean isNeedRateLimit() {
        return needRateLimit;
    }

    public TaskHandlerWrapper setNeedRateLimit(boolean needRateLimit) {
        this.needRateLimit = needRateLimit;
        return this;
    }

    public boolean isEnableAddTaskIfUnableExecute() {
        return enableAddTaskIfUnableExecute;
    }

    public TaskHandlerWrapper setEnableAddTaskIfUnableExecute(boolean enableAddTaskIfUnableExecute) {
        this.enableAddTaskIfUnableExecute = enableAddTaskIfUnableExecute;
        return this;
    }

    public boolean isEnableExecute() {
        return enableExecute;
    }

    public TaskHandlerWrapper setEnableExecute(boolean enableExecute) {
        this.enableExecute = enableExecute;
        return this;
    }

    public String getDefaultTaskGroupIfUnableExecute() {
        return defaultTaskGroupIfUnableExecute;
    }

    public TaskHandlerWrapper setDefaultTaskGroupIfUnableExecute(String defaultTaskGroupIfUnableExecute) {
        this.defaultTaskGroupIfUnableExecute = defaultTaskGroupIfUnableExecute;
        return this;
    }
}
